<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%String path = request.getContextPath();%>
<script type="text/javascript" src="<%=path%>/projectjs/ImageFileUpload.js"></script>
<script src="<%=path %>/js/dwz.tab.js" type="text/javascript"></script>
<script src="<%=path %>/projectjs/cardEntity.js" type="text/javascript"></script>
<script type="text/javascript">
	function addEntity(obj){
		if (!iu1.validate()) {
			alert("您还有像素为：【"+iu1.need_add_pic_pixel.join(",")+"】的未激活图片要添加，请添加图片！");
			iu1.openAddImgFrame();
			return false;
		}
		if (!iu2.validate()) {
			alert("您还有像素为：【"+iu2.need_add_pic_pixel.join(",")+"】的已激活图片要添加，请添加图片！");
			iu2.openAddImgFrame();
			return false;
		}
		if (!checkDate("inp_dateFrom","inp_dateTo"))return false;
		if($("#edit_cardEntity_cardLever").val()=="-1"){
			alertMsg.error("请选择会员卡级别！");
			return false;
		}
		if($("#edit_cardEntity_cardAgio").val()=="-1"){
			alertMsg.error("请选择基础折扣！");
			return false;
		}
		if($("#sel_cardEntityEdit_applyway").val()=="-1"){
			alertMsg.error("请选择申请方式！");
			return false;
		}
		var limitAmount = $("#inp_cardEntityEdit_limitAmount").val();
		if (limitAmount != "") {
			limitAmount=checkNum(limitAmount);
			if(limitAmount==""){
				alertMsg.error("您输入的数量有误！");
				return false;
			}
			$("#inp_cardEntityEdit_limitAmount").val(limitAmount);
		}
		selectCardEntityFileds();
		return validateCallback(obj, navTabAjaxDone);
	}
	function selectCardEntityFileds(){
		var fileds = "";
		$('input[type="checkbox"][name="fileds"]:checked').each(
				function(){ 
		     		fileds += $(this).val() + ","; 
				}
            );
        $("#postFileds").val(fileds);
	}
</script>
  <head>
    <title>编辑用户</title>
  </head>
  <body>
	<div class="pageContent">
		<div class="tabs" currentIndex="0" eventType="click">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li><a href="javascript:;"><span>基本信息</span></a></li>
					<li><a href="<%=path %>/cardCountInit/listCardCountInit.action?customerId=${cardEntityVO.customerId}&cardEntityId=${cardEntityVO.id}" class="j-ajax"><span>初始计次</span></a></li>
					<li><a href="<%=path %>/rechargeRule/listRechargeRule.action?cardEntityId=${cardEntityVO.id}" class="j-ajax"><span>充值规则</span></a></li>
					<li><a href="<%=path %>/upgradeRule/listUpgradeRule.action?cardEntityId=${cardEntityVO.id}&customerId=${cardEntityVO.customerId}" class="j-ajax"><span>升级规则</span></a></li>
					<li><a href="<%=path %>/serviceInit/listServiceInit.action?serviceInitVO.cardEntity.id=${cardEntityVO.id}" class="j-ajax"><span>初始服务</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" style="height:502px;">
			<div class="pageContent">
		<form method="post" action="<%=path %>/cardEntity/saveCardEntity.action" class="pageForm required-validate" onsubmit="return addEntity(this);">
			<div class="pageFormContent" layoutH="90">
				<input name="cardEntityVO.id" type="hidden" value="<s:property value="cardEntityVO.id" />" />
				<input type="hidden" name="cardEntityVO.customerId" value="<s:property value="cardEntityVO.customerId" />"/>
				<p>
					<label>会员卡方案编码：</label>
					<input name="cardEntityVO.schemeCode" value="<s:property value="cardEntityVO.schemeCode" />" class="required" type="text" size="30" readonly="readonly"/>
				</p>
				<p>
					<label>商户编码：</label>
					<input name="cardEntityVO.merchantCode" value="<s:property value="cardEntityVO.merchantCode" />" class="required" type="text" size="30" readonly="readonly">
					<c:if test="${SESSION_USER.customer==null}">
						<a class="btnLook" href="<%=path%>/customer/listCustomer.action?searchType=cardEntity&lookUpPre=edit" lookupGroup="cardEntityVO">选择</a>
					</c:if>
				</p>
				<p>
					<label>会员卡名称：</label>
					<input name="cardEntityVO.cardName" value="<s:property value="cardEntityVO.cardName" />" class="required" type="text" size="30" />
				</p>
				<p>
					<label>商户名：</label>
					<input name="cardEntityVO.merchantNamer" value="<s:property value="cardEntityVO.merchantNamer" />" class="required" type="text" size="30" readonly="readonly"/>
					
				</p>
				<p>
					<label>会员卡级别：</label>
					<input type="hidden" id="edit_db_cardEntity_cardLever" value="<s:property value="cardEntityVO.cardLever" />"/>
					<select name="cardEntityVO.cardLever" id="edit_cardEntity_cardLever">
							<option value="-1">请选择</option>
                            <c:forEach var="item" items="${cardLevelList}">
                                <option value="${item.id}" ${cardEntityVO.cardLever eq item.id?"selected":"" }>${item.levelName}</option>
                            </c:forEach>
	              	</select>
				</p>
				<p>
					<label>有效期开始：</label>
					<input id="inp_dateFrom" name="cardEntityVO.expiryDateFrom" value="<s:date name="cardEntityVO.expiryDateFrom" format="yyyy-MM-dd" />" readonly="true" class="date" type="text" size="20" /><a class="inputDateButton" href="javascript:;">选择</a>
				</p>
				<p>
					<label>有效期截止：</label>
					<input id="inp_dateTo" name="cardEntityVO.expiryDateTo" value="<s:date name="cardEntityVO.expiryDateTo" format="yyyy-MM-dd" />" readonly="true" class="date" type="text" size="20"/><a class="inputDateButton" href="javascript:;">选择</a>
				</p>
				<p>
					<label>申请方式：</label>
					<select id="sel_cardEntityEdit_applyway" name="cardEntityVO.applyWay" class="combox">
						<option value="-1">请选择</option>
						<option value="1" <c:if test="${cardEntityVO.applyWay==1}">selected='selected'</c:if> >商家自发</option>
						<option value="2" <c:if test="${cardEntityVO.applyWay==2}">selected='selected'</c:if> >商家自发+自主申请</option>
						<option value="3" <c:if test="${cardEntityVO.applyWay==3}">selected='selected'</c:if> >自主申请</option>
              		</select>
				</p>
				<p>
					<label>基础折扣：</label>
					<input type="hidden" id="edit_db_cardEntity_cardAgio" value="<s:property value="cardEntityVO.baseDiscount" />"/>
					<select name="cardEntityVO.baseDiscount" id="edit_cardEntity_cardAgio">
							<option value="-1">请选择</option>
                            <c:forEach var="item" items="${cardAgioList}">
                                <option value="${item.id}" ${cardEntityVO.baseDiscount eq item.id?"selected":"" }>${item.name}</option>
                            </c:forEach>
	              	</select>
				</p>
				<p>
					<label>数量限制：</label>
					<input id="inp_cardEntityEdit_limitAmount" name="cardEntityVO.limitAmount" value="<s:property value="cardEntityVO.limitAmount" />" class="required" type="text" size="15" alt="请输入数量限制"/>
				</p>
				<p>
					<label>是否推荐：</label>
					<s:select name="cardEntityVO.isRecommend"
							list="%{#{0:'否',1:'是'}}" listKey="key" listValue="value" cssClass="combox"></s:select>
				</p>
				<p>
					<label>是否热门：</label>
					<s:select name="cardEntityVO.isHot"
							list="%{#{0:'否',1:'是'}}" listKey="key" listValue="value" cssClass="combox"></s:select>
				</p>
				<div class="divider" style="border: 0"></div>
					<dl class="nowrap">
						<dt>折扣描述：</dt>
						<dd>
						<textarea class="textInput required" rows="2" cols="80" name="cardEntityVO.agioInfo" style="align:left; width: 510px; height: 80px;"><s:property value="cardEntityVO.agioInfo" /></textarea>
						</dd>
					</dl>
				<div class="divider" style="border: 0"></div>
					<dl class="nowrap">
						<dt>会员福利：</dt>
						<dd>
						<textarea class="textInput required" rows="2" cols="80" name="cardEntityVO.welfare" style="align:left; width: 510px; height: 80px;"><s:property value="cardEntityVO.welfare" /></textarea>
						</dd>
					</dl>
				<div class="divider" style="border: 0"></div>
					<dl class="nowrap">
						<dt>使用须知：</dt>
						<dd>
						<textarea class="textInput required" rows="2" cols="80" name="cardEntityVO.useNotes" style="align:left; width: 510px; height: 80px;"><s:property value="cardEntityVO.useNotes" /></textarea>
						</dd>
					</dl>
					<label>可选录入项：</label>
					<input type="hidden" id="postFileds" name="cardEntityVO.inputFileds" value="<s:property value="cardEntityVO.inputFileds"/>"/>
					<dl style="width:700px">
						<dt><input type="checkbox" name="fileds" value="email" ${fn:contains(cardEntityVO.inputFileds,'email') ? 'checked=checked' : ''}/>会员Email</dt>
						<dt><input type="checkbox" name="fileds" value="qq" ${fn:contains(cardEntityVO.inputFileds,'qq') ? 'checked=checked' : ''}/>会员QQ</dt>
						<dt><input type="checkbox" name="fileds" value="address" ${fn:contains(cardEntityVO.inputFileds,'address') ? 'checked=checked' : ''}/>会员联系地址</dt>
						<dt><input type="checkbox" name="fileds" value="idcard" ${fn:contains(cardEntityVO.inputFileds,'idcard') ? 'checked=checked' : ''}/>会员身份证号</dt>
						<dt><input type="checkbox" name="fileds" value="birthday" ${fn:contains(cardEntityVO.inputFileds,'birthday') ? 'checked=checked' : ''}/>会员出生日期</dt>
					</dl>
				<div class="divider"></div>
				<p style="width: 98%;height: auto;">
						<label>未激活图片：</label>
						<a class="button" onclick="openAddImgFrame(1);"><span>添加图片</span></a>
						<a class="btnAttach" id="add_pic_a_id1" href="<%=path%>/jsp/common/image_file_upload.jsp" lookupGroup="attachment" width="560" height="300" style="display: none"></a>
						<div class="divider" style="border:0"></div>
						<div id="pic_need_add_pixel_div1"></div>
						<div class="divider" style="border:0"></div>
						<div id="pic_content_div1" style="float: none;width:auto;padding-left: 150px;width:720px">
					<s:iterator value="cardEntityVO.nonactivatedPic.split(',')" id="picName" status="i">
						<div id="pic_div_old_${i.index}" style="border:1 solid #ccc;margin-top:5px;margin-bottom:5px;padding:5px;">
							<b>图片像素：</b>宽<s:property value="#picName.split('_')[1]"/>高<s:property value="#picName.split('_')[2]"/>
							<b style="margin-left:15px">图片：</b><a href="<%=path%>/jsp/common/preview_image.jsp?folder=card&picNames=${picName}&id=${cardEntityVO.id}" target="dialog" rel="" max="true" title="预览图片" width="800" height="480" style="margin-right: 40px">${picName}</a>
							<a href="javascript:;" onclick="removePicContent('pic_div_old_${i.index}','<s:property value="#picName.split('_')[1]"/>_<s:property value="#picName.split('_')[2]"/>','${picName}',1);">移除</a>
						</div>
					</s:iterator>
						</div>	
					</p>
				    <div class="divider"></div>
				    <p style="width: 98%;height: auto;">
						<label>已激活图片：</label>
						<a class="button" onclick="openAddImgFrame(2);"><span>添加图片</span></a>
						<a class="btnAttach" id="add_pic_a_id2" href="<%=path%>/jsp/common/image_file_upload.jsp" lookupGroup="attachment" width="560" height="300" style="display: none"></a>
						<div class="divider" style="border:0"></div>
						<div id="pic_need_add_pixel_div2"></div>
						<div class="divider" style="border:0"></div>
						<div id="pic_content_div2" style="float: none;width:auto;padding-left: 150px;width:720px">
					<s:iterator value="cardEntityVO.activatedPic.split(',')" id="picName" status="i">
						<div id="pic_div_old_${i.index}" style="border:1 solid #ccc;margin-top:5px;margin-bottom:5px;padding:5px;">
							<b>图片像素：</b>宽<s:property value="#picName.split('_')[1]"/>高<s:property value="#picName.split('_')[2]"/>
							<b style="margin-left:15px">图片：</b><a href="<%=path%>/jsp/common/preview_image.jsp?folder=card&picNames=${picName}&id=${cardEntityVO.id}" target="dialog" rel="" max="true" title="预览图片" width="800" height="480" style="margin-right: 40px">${picName}</a>
							<a href="javascript:;" onclick="removePicContent('pic_div_old_${i.index}','<s:property value="#picName.split('_')[1]"/>_<s:property value="#picName.split('_')[2]"/>','${picName}',2);">移除</a>
						</div>
					</s:iterator>
						</div>	
					</p>
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
					</li>
				</ul>
			</div>
		</form>
	</div>
			<div>
			</div>
			<div>
			</div>
			<div>
			</div>
			<div>
			</div>
			<div>
			</div>
	</div>
	</div>
</div>
<script type="text/javascript">
var iu1 = new ImageUpload("${cardEntityVO.nonactivatedPic}","card","1","${pageContext.request.contextPath}","cardEntityVO.nonactivatedPic");
var iu2 = new ImageUpload("${cardEntityVO.activatedPic}","card","2","${pageContext.request.contextPath}","cardEntityVO.activatedPic");
</script>